// pages/Archives/Specifications/index.js.
const netWorked = require('../../../utils/netWork.js')
const Config = require('../../../utils/confing.js')
Page({
  /**
   * 页面的初始数据
   */
  data: {
    activeNames: ['1'],
    data: [],
    show: false,
    phone: '',//
    account: '',//
    name: '',//
    password: '',//

    qqnumber: '',//
    WeChat: '',//
    address: '',//

    shenhe: "全部",
    shenheshow: false,

    addshow:false,

    typeid:0,
  },
  input1(e) {
    let phone = e.detail
    this.setData({
      phone
    })
  },
  input2(e) {
    let account = e.detail
    this.setData({
      account
    })
  },
  input3(e) {
    let name = e.detail
    this.setData({
      name
    })
  },
  input4(e) {
    let password = e.detail
    this.setData({
      password
    })
  },
  input5(e) {
    let qqnumber = e.detail
    this.setData({
      qqnumber
    })
  },
  input6(e) {
    let WeChat = e.detail
    this.setData({
      WeChat
    })
  },
  input7(e) {
    let address = e.detail
    this.setData({
      address
    })
  },


  add(){
    let _this = this

    _this.setData({
      phone: '',//规格
      account: '',//规格
      name: '',//规格
      qqnumber: '',//规格
      WeChat: '',//规格
      address: '',//规格
      password: '',//规格
      typeid:0,
    })
    _this.setData({
      addshow: true,
    })
  },
  addhide(){
    let _this = this
    _this.setData({
      addshow: false,
    })
  },
  //审核框
  shenheshow() {
    let _this = this
    _this.setData({
      shenheshow: true,
    })
  },
  //选中审核状态
  onSearch(e) {
    let _this = this

    if (e.currentTarget.dataset.shen == "-1") {
      wx.request({
        url: Config.BaseUrl + 'Archives/SelCustomer',
        method: "POST",
        success: function (res) {
          let data = res.data
          _this.setData({
            data: res.data,
            shenheshow: false,
            shenhe: "全部",
          })

        }
      })
    }

    else if (e.currentTarget.dataset.shen == "1") {

      wx.request({
        url: Config.BaseUrl + "Archives/SelCustomer?where=status='False'",
        method: "POST",
        success: function (res) {
          let data = res.data
          _this.setData({
            data: res.data,
            shenheshow: false,
            shenhe: "未审核",
          })

        
        }
      })



    } else {
      _this.setData({
        shenhe: "已审核",
      })
      wx.request({
        url: Config.BaseUrl + "Archives/SelCustomer?where=status='True'",
        method: "POST",
        success: function (res) {
          let data = res.data
          _this.setData({
            data: res.data,
            shenheshow: false,
            shenhe: "已审核",
          })

        
        }
      })
    }

  },
  //搜索
  onSearchs(e) {
    console.log('123');
    let where = "account like '" + e.detail + "%25' or phone like '%25" + e.detail + "%25'";
    let _this = this
    netWorked.netWork({
      url: 'Archives/SelCustomer?where=' + where,
      method: "POST",
      success: function (res) {
        console.log(res.data)
        let data = res.data
        _this.setData({
          data: res.data
        })
      }
    })

  },
 
  //删除
  delete(event) {
    let id = event.currentTarget.dataset.id;
    wx.showModal({
      title: '提示',
      content: '确定要删除嘛？',
      success: function (res) {
        if (res.confirm) {
          wx.request({
            url: Config.BaseUrl + 'Archives/DelCustomer?id=' + id,
            method: "POST",
            success: function (res) {
              // console.log(res.data)

              wx.showToast({
                title: '删除成功',
                icon: "none",
              })


              //刷新页面
              const pages = getCurrentPages()
              const perpage = pages[pages.length - 1]
              perpage.onLoad()

            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })

  },
  //编辑
  exet(event) {
    this.setData({
      addshow: true,
      typeid:1,
    })
    let _this = this
    let id = event.currentTarget.dataset.id;
    // console.log(event.currentTarget.dataset.id);

    let where = " account='" + id + "'";

    wx.request({
      url: Config.BaseUrl + 'Archives/SelCustomer?where=' + where,
      method: "POST",
      // data: where=where,
      success: function (res) {
        // console.log(res.data)

        _this.setData({
          phone: res.data[0].phone,//规格
          account: res.data[0].account,//规格
          name: res.data[0].name,//规格
          qqnumber: res.data[0].qqnumber,//规格
          WeChat: res.data[0].WeChat,//规格
          address: res.data[0].address,//规格
          password: res.data[0].password,//规格
        })
      }
    })



  },
  //新增保存
  addok(event) {
    let _this = this;

  

    wx.request({
      url: Config.BaseUrl + 'Archives/UpdOperator?account=' + this.data.account + '&name=' + this.data.name + '&password=' + this.data.password + '&qqnumber=' + this.data.qqnumber + '&WeChat=' + this.data.WeChat + '&address=' + this.data.address + '&phone=' + this.data.phone + '&&typeid=' + this.data.typeid+'',
      method: "POST",
     
      success: function (res) {
      

        if (res.data == 1) {
          wx.showToast({
            title: '保存成功',
            icon: "none",
          })


          _this.setData({
            addshow: false,
          })

          //刷新页面
          const pages = getCurrentPages()
          const perpage = pages[pages.length - 1]
          perpage.onLoad()
        } else {
          wx.showToast({
            title: '保存失败',
            icon: "none",
          })

         
        }

      }
    })

  },
  onChange(event) {
    this.setData({
      activeNames: event.detail
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let _this = this
    netWorked.netWork({
      url: 'Archives/SelCustomer',
      method: "POST",

      success: function (res) {
        console.log(res.data)
        let data = res.data
        _this.setData({
          data: res.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})